﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using TeBigScreenWpf.ViewModels;

namespace TeBigScreenWpf.Pages
{
    /// <summary>
    /// Interaction logic for Page9.xaml
    /// </summary>
    public partial class Page9 : Page
    {
        public Page9()
        {
            InitializeComponent();

            DataContext = vmGlobal.vmPage.Value;

            this.Loaded += Page9_Loaded;
        }

        private double _initWindowScale;

        private void Page9_Loaded(object sender, RoutedEventArgs e)
        {
            var rect = new Rect(122.522972217755, 45.4248047848192, 3.66945357079578, 1.89817313630427);

            this.GeoMap.ZoomToGeographic(rect);
            this.GeoMap2.ZoomToGeographic(rect);
            this.GeoMap3.ZoomToGeographic(rect);

            this.GeoMap.WindowRectChanged += GeoMap_WindowRectChanged;

            //LoadMap();
        }

        private void GeoMap_WindowRectChanged(object sender, Infragistics.RectChangedEventArgs e)
        {
            HeatSeries.PointExtent = (int)Math.Round(12 * _initWindowScale / this.GeoMap.ActualWindowScale);
        }

        private void LoadMap()
        {
            _initWindowScale = this.GeoMap.ActualWindowScale;

            //var heat = vmGlobal.vmPage.Value.Heat;

            //TriangulationSource triangulationData = TriangulationSource.Create(heat.Count,
            //    (i) => new Point(heat[i].Coord.Longitude, heat[i].Coord.Latitude),
            //    (i) => heat[i].Value);

            //ScatterAreaSeries.ItemsSource = triangulationData.Points;
            //ScatterAreaSeries.TrianglesSource = triangulationData.Triangles;

            HeatSeries.LongitudeMemberPath = "Coord.Longitude";
            HeatSeries.LatitudeMemberPath = "Coord.Latitude";
            HeatSeries.UseBruteForce = true;
            HeatSeries.HeatMinimumColor = Color.FromArgb(0x2f, 0x00, 0x80, 0x00);
            HeatSeries.HeatMaximumColor = Color.FromArgb(0x2f, 0xff, 0xa5, 0x00);
            HeatSeries.HeatMinimum = 0;
            HeatSeries.HeatMaximum = 22;

            //HeatSeries.Resolution = 10;

            //HeatSeries.ItemsSource = vmGlobal.vmPage.Value.Heat;

            //ProportionalSymbolSeries.LongitudeMemberPath = "Coord.Longitude";
            //ProportionalSymbolSeries.LatitudeMemberPath = "Coord.Latitude";
            //ProportionalSymbolSeries.RadiusMemberPath = "Value";
            //ProportionalSymbolSeries.FillMemberPath = "Value";

            //ProportionalSymbolSeries.ItemsSource = vmGlobal.vmPage.Value.Heat;
        }

        private void GeoMap_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var xxx = GeoMap.GetGeographicFromZoom(GeoMap.WindowRect);
            var zzz = xxx;
        }
    }
}